public class Solution {
    public int maxSubArray(int[] nums) {
        int len = nums.length;

        int[] dp = new int[len];

        dp[0] = nums[0];

        for (int i = 1; i < len; i++) {
            dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
        }

        int ret = Integer.MAX_VALUE * (-1);

        for (int num : dp) {
            ret = Math.max(ret, num);
        }

        return ret;
    }
}
